package de.hska.util;

import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class MessagesUtil {
	private static Locale locale = Locale.getDefault();
	// Locale.GERMAN fuer feste Einstellung auf deutsch
	// Locale.ENGLISH fuer feste Einstellung auf englisch
	
	private static String MESSAGES = "de.hska.nls.messages";
	private static ResourceBundle resourceBundle = ResourceBundle.getBundle(MESSAGES, locale);
	static {
		if (resourceBundle == null) {
			Log log = LogFactory.getLog(MessagesUtil.class);
			log.fatal("FATAL ERROR: " + MESSAGES + " not found");
			log = null;
		}
	}
	
	public static String getMessage(String key, Object... args) {
		final String msgPattern = resourceBundle.getString(key);
		MessageFormat formatter = new MessageFormat(msgPattern);
		String msg = formatter.format(args);
		return msg;
	}
}
